﻿<?xml version="1.0" encoding="utf-8"?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="ACompany.OrderProcessing.Model"
                   assembly="ACompany.OrderProcessing.Model">
  <class name="Order" table="Orders" lazy="false">
    <id name="Id" column="id" type="guid">
      <generator class="guid" />
    </id>
    
    <version name="version" access="field.camelcase-underscore" column="version" />
    
    <component name="DespatchAddress" class="ACompany.OrderProcessing.Model.Address">
      <!-- class attribute optional -->
      <property access="field.camelcase-underscore" column="DespatchStreet" name="Street" />
      <property access="field.camelcase-underscore" column="DespatchCity" name="City" />
      <property access="field.camelcase-underscore" column="DespatchCountry" name="Country" />
      <property access="field.camelcase-underscore" column="DespatchPostCode" name="PostCode" />
    </component>

    <property name="OrderDate">
      <column name="Date" not-null="true" />
    </property>

    <property name="Status" access="field.camelcase-underscore">
      <column name="status" not-null="true" />
    </property>

    <!-- Many-to-one mapping: Customer -->
    
    <many-to-one name="Customer"  class="Customer" column="CustomerID" cascade="none" not-null="true" />
    
    <!-- One-to-many mapping: Addresses 			need to add inverse="true" otherwise
			the SQL throws NULL error						cascade="all-delete-orphan"						lazy="true"??
			fetch="join"??		-->

    <bag name="Items" access="field.camelcase-underscore" inverse="true" cascade="all" lazy="true">
      <key column="OrderID" />      
      <one-to-many class="Item" />
    </bag>

  </class>

</hibernate-mapping>